/*  
 * cafe-alarmlegend.js
 * 报警图例
 */
;define(function(){
	'use strict';
	function getNodeHtml(cfg){
		$(cfg.appendTo).find(".cafe-busis-alarmlegend").remove();
		var $container = $('<div class="cafe-busis-alarmlegend">');
		
		
		return $container;
	}
	
	function bindEvent($drop, cfg){
		$drop.find(".time-title").off('click').on('click', function() {
			var $li = $(this).nextAll();
			var visibleLiLen = $('.cafe-busis-timeline ul.selected').find("li:visible").length;
			if ($li.length + visibleLiLen > 23) {
				$('.cafe-busis-timeline').find("ul.selected").removeClass("selected");
			}
			$(this).parent().addClass("selected");
		})
	}
	
	var CFAlarmlegend = function(settings){
		var options = {
				appendTo: '',  // 时间轴所在容器
				mapId: [],     // 地图ID
				title: ''      // 标题
		};
		this.config = $.extend({},options, settings);
		this.$drop = getNodeHtml(this.config);
		bindEvent(this.$drop, this.config);
		if(this.config.appendTo){
			$(this.config.appendTo).append(this.$drop);
		}
	}
	
	CFAlarmlegend.prototype = {
		close: function() {
			this.$drop.hide();
		}
	};
	
	CafeJS.Alarmlegend = function(settings){
		var drop = new CFAlarmlegend(settings);
		return drop;
	}
});